<?php

namespace app\index\controller;

use app\common\Model\Coupons;
use controller\BasicApi;


/**
 * 应用入口控制器
 * @author Vilson
 */
class CouponsController extends BasicApi{

    public
    function index(){
        $this->success('success CouponsController');
    }

    /**
     * 分页
     */
    public
    function page(){
        $coupons_model = new Coupons();
        $this->return_json($coupons_model->get_page($this->get_req_params(),$this->get_page_param()));
    }

    /**
     * 详情
     */
    public
    function detail(){
        $id            = input('id');
        $coupons_model = new Coupons();
        $ret           = $coupons_model->find($id);
        if(empty($ret)){
            $this->return_json(4004, '', $ret);
        }
        $ret                = $ret->toArray();
        $ret['picurl_list'] = explode(';', $ret['picurls']);
        ksort($ret);
        $this->return_json(2000, '', $ret);
    }

    /**
     *高效转链
     */
    public
    function get_privilege_link(){
        $id            = input('id');
        $coupons_model = new Coupons();
        $ret           = $coupons_model->find($id);
        if(empty($ret)){
            $this->return_json(4004, '商品不存在', $ret);
        }

        $this->return_json($coupons_model->get_privilege_link($ret));
    }


}
